package yunwo.cn.yzstation.model;

import android.util.Log;

import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.request.RequestCall;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IorderActivityModel;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.base.Yzapp;
import yunwo.cn.yzstation.bean.PackProductBean;
import yunwo.cn.yzstation.bean.Waybillbean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.view.activity.OrderActivity;

/**
 * Created by lao on 2017/9/11.
 */
public class OrderActivityModel {

    OrderActivity orderActivity;
    IorderActivityModel iorderActivityModel;

    public OrderActivityModel(OrderActivity orderActivity, IorderActivityModel iorderActivityModel) {
        this.orderActivity = orderActivity;
        this.iorderActivityModel = iorderActivityModel;
    }





    public void getWayBill() {
        RequestCall build = OkHttpUtils.post().url(MyConstants.Waybill)
                .addHeader("Authorization", Yzapp.getInstance().getAuthorization())
                .build();
        build.execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (!result.equals("\"\"")&&!result.equals("")){
                    Waybillbean.DataBean dataBean = new Gson().fromJson(result, Waybillbean.DataBean.class);
                    iorderActivityModel.getWayBillSuccess(dataBean);
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {

            }
        });
    }
// 获取默认品名包装
    public void getPackProduct() {
        Map<String, Object> map = new HashMap<>();
        HttpManager.hpptPostString3(MyConstants.getPackProduct,map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("\"\"")&&!result.equals("")) {
                        PackProductBean.DataBean dataBean = new Gson().fromJson(result, PackProductBean.DataBean.class);
                        iorderActivityModel.getPackProductSuccess(dataBean);

                   /*     if (mGoodsTV != null && mPackingTV != null) {
                            mGoodsTV.setText(dataBean.getProductName());
                            mPackingTV.setText(dataBean.getPackName());
                        }
                        Yzapp.getInstance().getinfoSPEditor().putString("packName", dataBean.getPackName());
                        Yzapp.getInstance().getinfoSPEditor().putString("productName", dataBean.getProductName());
                        Yzapp.getInstance().getinfoSPEditor().commit();*/
                    }
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {

            }
        });

    }
}



/*new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.d("aaaaaaaaaa", e.toString());
            }

            @Override
            public void onResponse(String response, int id) {
                Log.d("aaaaaaaaaa", response);
            }
        }*/

/*new WaybillCallBack(Waybillbean.class,orderActivity,false){
            @Override
            public void myError(Call call, Exception e, int id) {
                Log.d("运单号", e.toString());
            }

            @Override
            public void onResponse(Waybillbean response, int id) {
                if (response.getCode() == 200) {
                    iorderActivityModel.getWayBillSuccess(response);
                }else {
                    Toast.makeText(orderActivity, response.getCode() + response.getMsg(), Toast.LENGTH_SHORT).show();
                }
            }
        }*/